package com.huawei.java.main.io;


import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
 * @author dengguoli
 * @date 2022/3/14
 * @since jdk1.8
 */
public class Reader {

    public static List<String[]> readCsvFile(String argPath) {
        String line = "";
        List<String[]> csvFile = new ArrayList<>();
        final String delimiter = ",";
        try {
            FileReader fileReader = new FileReader(argPath);

            BufferedReader reader = new BufferedReader(fileReader);
            while ((line = reader.readLine()) != null) {
                String[] token = line.split(delimiter);
                csvFile.add(token);
            }
        }
        catch (IOException e) {
            e.printStackTrace();
        }
        return csvFile;
    }

    public static Integer readIniFile(String argPath) {
        String line = "0";
        final String delimiter = "=";
        try {
            FileReader fileReader = new FileReader(argPath);
            BufferedReader reader = new BufferedReader(fileReader);
            int i = 0;
            while ((line = reader.readLine()) != null) {
                if (i == 1) {
                    String[] token = line.split(delimiter);
                    line = token[1];
                    break;
                }
                i ++;
            }
        }
        catch (IOException e) {
            e.printStackTrace();
        }
        return Integer.valueOf(line);
    }


}
